package baseClass;

import baseAPI.Database;

import java.sql.ResultSet;
import java.sql.SQLException;

public class RoomStatistics {//房间种类统计
        private int roomsLeft;
        private int roomsTotal;
        Database database;

        public RoomStatistics(Database database){
            this.database = database;
        }

        public void inquire(int roomKind){
            ResultSet resultSet = database.select("roomsLeft, roomsTotal", "roomStatistics", "roomKind = " + roomKind);
            try {
                if(resultSet.next()) {
                    roomsLeft = resultSet.getInt(1);
                    roomsTotal = resultSet.getInt(2);
                }
            }catch(SQLException ex){
                System.out.println("RoomStatisticsException");
            }
        }

        public int getRoomsLeft(){
            return roomsLeft;
        }

        public int getRoomsTotal(){
            return roomsTotal;
        }

        public static void update(int roomKind, int value, Database database){
            if(value == 1){
                database.update("roomStatistics", "roomsLeft", "roomsLeft + 1", "roomKind = " + roomKind);
            }
            else if(value == -1){
                database.update("roomStatistics", "roomsLeft", "roomsLeft - 1", "roomKind = " + roomKind);
            }
        }
}
